<!DOCTYPE html>
<html lang="zh">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
<meta name="keywords" content="LightYear,LightYearAdmin,光年,后台模板,后台管理系统,光年HTML模板">
<meta name="description" content="Light Year Admin V5是一个基于Bootstrap v5.1.3的后台管理系统的HTML模板。">
<title>{:$configs['SYSTEM_NAME']}</title>
<link rel="shortcut icon" type="image/x-icon" href="favicon.ico">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-touch-fullscreen" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="default">
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/materialdesignicons.min.css">
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/css/style.min.css">
<!--日期选择器css-->
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/js/bootstrap-datepicker/bootstrap-datepicker3.min.css">
<!--时间日期选择器css-->
<link rel="stylesheet" type="text/css" href="__STATIC__/admin/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.css">

<link rel="stylesheet" type="text/css" href="__STATIC__/common/cch.css">
<style type="text/css">
    .ok-btn {display:none;margin:0 5px 0 10px;}
    .no-btn {display:none;}

    .noedit-tr {background: #eee;}

    .user-div {font-size:16px;}
    .user-div code {font-size: 18px;font-family: 微软雅黑;}
</style>
</head>
  
<body>
<div class="container-fluid">
  
  <div class="row">
    
    <div class="col-lg-12">
      <div class="card">
        <div class="card-body">
          <div class="card-search mb-2-5">
            <form class="search-form" method="get" action="{:url('moreEdit')}" >
              <input type="hidden" name="user_id" value="{:$user['id']}" />
              {include file="html/search" /}
              
            </form>
          </div>
          <div class="card-btns mb-2-5">
            <a class="btn btn-primary me-1 search_btn" href="#!"><i class="mdi mdi-magnify"></i> 搜索</a>
            <button class="btn btn-info more_edit_btn" data-bs-toggle="modal" data-bs-target="#modal-edit"><i class="mdi mdi-pencil"></i> 编辑</button>
          </div>
          <div class="table-responsive">
            <div class="user-div">用户名称：<code>{:$user['name']}</code>
              &nbsp;&nbsp;
              总折扣：<code>{:$user['total_discount']}</code></div>
            <table class="table table-bordered">
              <thead>
                <tr>
                  <th>
                    <div class="form-check">
                      <input class="form-check-input" type="checkbox" id="check-all">
                      <label class="form-check-label" for="check-all"></label>
                    </div>
                  </th>
                  <th>名称</th>
                  <th>代码</th>
                  <th>折扣</th>
                </tr>
              </thead>
              <tbody>
                <?php if (empty($list)): ?>
                  <tr><td colspan="100" class="text-center">暂无数据</td></tr>
                <?php else: ?>
                  <?php foreach ($list as $k => $vo): ?>
                    <tr class="{:$vo['product_discount'] >= 1 ? 'noedit-tr' : ''}">
                      <td>
                        <?php if ($vo['product_discount'] < 1): ?>
                        <div class="form-check">
                          <input type="checkbox" class="form-check-input ids" name="ids[]" value="{:$vo['code']}" id="ids-{:$vo['id']}">
                          <label class="form-check-label" for="ids-{:$vo['id']}"></label>
                        </div>
                        <?php endif ?>
                      </td>
                      <td>{:$vo['name']}</td>
                      <td>{:$vo['code']}</td>
                      <td width="30%">
                          <?php if ($vo['product_discount'] < 1): ?>
                          <input type="text" name="discount" class="form-control discount-input" value="{:$vo['discount']}" data-code="{:$vo['code']}" data-val="{:$vo['discount']}" style="width: 50%;display:inline;" />
                          <a href="javascript:void(0);" class="btn btn-xs btn-success ok-btn" data-toggle="tooltip" title="确认"><i class="mdi mdi-check"></i></a>
                          <a href="javascript:void(0);" class="btn btn-xs btn-danger no-btn" data-toggle="tooltip" title="取消"><i class="mdi mdi-close"></i></a>
                          <?php endif ?>
                      </td>
                        
                 
                    </tr>
                  <?php endforeach ?>
                <?php endif ?>
              </tbody>
            </table>
          </div>

          {$page|raw}
          
          
        </div>
      </div>
    </div>
        
  </div>
  
</div>


<div class="modal" tabindex="-1" id="modal-edit">
  <div class="modal-dialog modal-dialog-centered">
    <div class="modal-content">
      <div class="modal-header">
        <h6 class="modal-title">编辑</h6>
        <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
      </div>
      <form action="{:url('moreUpdate')}" method="POST">
        <input type="hidden" name="code" />
        <input type="hidden" name="user_id" value="{:$user['id']}" />
        <div class="modal-body">
          <div class="row mb-3">
              <?php $field = 'discount'; $vo = ['name'=>'折扣','type'=>'text','value'=>'']; ?>
              <div class="col-md-12">
                {include file="html/fields/text" /}
              </div>
          </div>
        </div>
        <div class="modal-footer">
          <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">关闭</button>
          <button type="submit" class="btn btn-primary">保存</button>
        </div>
      </form>
    </div>
  </div>
</div>





<script type="text/javascript" src="__STATIC__/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/popper.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/bootstrap.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/main.min.js"></script>
<!--日期选择器js-->
<script type="text/javascript" src="__STATIC__/admin/js/bootstrap-datepicker/bootstrap-datepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/bootstrap-datepicker/locales/bootstrap-datepicker.zh-CN.min.js"></script>
<!--时间日期选择器js-->
<script type="text/javascript" src="__STATIC__/admin/js/momentjs/moment.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/bootstrap-datetimepicker/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/momentjs/locale/zh-cn.min.js"></script>
<script type="text/javascript" src="__STATIC__/admin/js/lyear-loading.js"></script><!-- loading -->
<!--自定义扩展-->
<script type="text/javascript" src="__STATIC__/common/cch.js"></script>
</body>
<script type="text/javascript">
    $(function(){
        $("input[name='discount']").on('keyup',function(){
            var cur_discount = parseFloat($(this).val());
            if ( cur_discount > 0 && cur_discount <= 1 && cur_discount != parseFloat($(this).attr('data-val')) ) {
                $(this).nextAll('.ok-btn').show();
                $(this).nextAll('.no-btn').show();
            }else{
                $(this).nextAll('.ok-btn').hide();
                $(this).nextAll('.no-btn').hide();
            }
        });
        $(".ok-btn").on('click',function(){
            var discount_input = $(this).prevAll('.discount-input');
            $.ajax({
                url:'{:url("updateDiscount")}',
                data:{user_id:'{:$user['id']}',product:$(discount_input).attr('data-code'),discount:$(discount_input).val()},
                type:'post',
                dataType:'json',
                success:function(data){
                    console.log(data);
                    if (data.status == 1) {
                        $(discount_input).val(data.discount);
                        $(discount_input).attr('data-val',data.discount);
                        $(discount_input).trigger('keyup');
                    }else{
                        alert(data.msg);
                    }
                }
            });
        });
        $(".no-btn").on('click',function(){
            $(this).prevAll('.discount-input').val($(this).prevAll('.discount-input').attr('data-val'));
            $(this).hide();
            $(this).prevAll('.ok-btn').hide();
        });
    });
</script>
<script type="text/javascript">
    $(".more_edit_btn").on('click',function(){
        var ids = [];
        $(".ids:checked").each(function(){
            ids.push($(this).val());
        });
        if (ids.length == 0) {
            alert('请勾选选项');
            return false;
        }
        $("#modal-edit").find('input[name="code"]').val(ids.join(','));
    });
</script>
</html>